/*
 * CodeSaveCommand.java
 *
 * Created on 2006년 3월 29일 (수), 오후 4:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.joinhawaii.home;

import java.util.*;

import java.io.File;
import javax.servlet.*;
import javax.servlet.http.*;

import com.zll.framework.model.HashList;
import com.zll.framework.servlet.Command;
import com.zll.framework.util.StringUtil;



/**
 *
 * @author eastar
 */
public class WordUpdateCommand implements Command
{

    public String execute(HttpServletRequest  request, HttpServletResponse response)
    throws Exception
    {
    	System.out.println("▶▶▶ Start "+this.getClass().getName());

    	String userid 				= StringUtil.nvl(request.getSession().getAttribute("session.userid"), "guest");
    	String work					= StringUtil.nvl(request.getParameter("work"));
    	String pmenu_id				= StringUtil.nvl(request.getParameter("pmenu_id"));
    	String menu_id				= StringUtil.nvl(request.getParameter("menu_id"));
    	String target				= StringUtil.nvl(request.getParameter("target"));



		String job_type 			= StringUtil.nvl(request.getParameter("job_type"));
		String word_id     			= StringUtil.nvl(request.getParameter("word_id"));
		String password         	= StringUtil.nvl(request.getParameter("password"));
		String board_id     		= StringUtil.nvl(request.getParameter("board_id"));
		String subject      		= StringUtil.toHan(request.getParameter("subject"));
		String open_yn      		= StringUtil.nvl(request.getParameter("open_yn"));
		String content      		= StringUtil.toHan(request.getParameter("content"));
		String author_name      	= StringUtil.toHan(request.getParameter("author_name"));
		String email		      	= StringUtil.toHan(request.getParameter("email"));
		String telephone	      	= StringUtil.toHan(request.getParameter("telephone"));


		BoardDAO boardDAO = new BoardDAO();

		HashMap infos 	= new HashMap();

		infos.put("word_id",		word_id);

		HashList wordList 	= boardDAO.selectWordDetail(infos);

		if (!password.equals(wordList.get("password",0)))
		{
			HashMap result	= new HashMap();

    		result.put("result", 	"true");
			result.put("target",	target);
			result.put("message",	"비밀번호가 일치하지 않습니다.");
			result.put("action",	"./boardView.jsp?word_id="+word_id+"&board_id="+board_id+"&pmenu_id="+pmenu_id+"&menu_id="+menu_id);

	    	request.setAttribute("result", result);

	    	return "/common/move_view.jsp";
		}
		else
		{
			if ("U".equals(job_type))
			{
		   		infos.put("job_type", 		job_type 	);
	    		infos.put("board_id",     	board_id   	);
	    		infos.put("subject",      	subject    	);
	    		infos.put("password",     	password   	);
	    		infos.put("open_yn",      	open_yn    	);
	    		infos.put("content", 	 	content);//infos.put("content",      	StringUtil.replaceContent(content, "img/pic/board/"+board_id));
	    		infos.put("author_name",  	author_name	);
	    		infos.put("email",			email		);
	    		infos.put("telephone",		telephone	);
	    		infos.put("up_user",		userid		);
	    	}
	    	else if ("D".equals(job_type))
	    	{
	    		infos.put("job_type", 		job_type 	);
		   	}

			/* update word */
			boolean bResult			= boardDAO.saveWord(infos);

			HashMap result	= new HashMap();

			if (bResult) {
				result.put("result", 	"true");
				result.put("target",	target);

				if (job_type.equals("U")) {
					result.put("action",	"/home/boardView.jsp?word_id="+word_id+"&board_id="+board_id+"&pmenu_id="+pmenu_id+"&menu_id="+menu_id);
				} else {
					result.put("action",	"/home/boardList.jsp?board_id="+board_id+"&pmenu_id="+pmenu_id+"&menu_id="+menu_id);
				}

		    	request.setAttribute("result", result);

		    	return "/common/move_view.jsp";
		    } else {
		    	return "/common/error_page.jsp";
		    }
		}
    }
}
